/**
 * 题目链接：2025/10/28 考试 T3 树上的回忆 II
 * 完成时间：2025/10/28 15:30
 * 简要思路：
 */
#include <bits/stdc++.h>
#define range(i, b, e) for (auto i(b); i != (e); i++)
#define rep(i, b, e) for (auto i(b); i <= (e); i++)
#define req(i, b, e) for (auto i(b); i >= (e); i--)
using namespace std;
typedef long long LL;
typedef pair<int, int> Pii;

const int N = 2e5, W = 18;
int n, q;
int ecnt, hed[N+5], to[N*2 + 5], w[N*2 + 5], nxt[N*2 + 5];
int dcnt, dfn[N+5], rfn[N+5], dfnid[N+5], dep[N+5];
int fa[N+5][W+1];
LL sum[N+5];
LL lstans;
int rmqLCA[N+5][W+1];

void Addedge(int u, int v, int ew) {
	to[++ecnt] = v;
	w[ecnt] = ew;
	nxt[ecnt] = hed[u];
	hed[u] = ecnt;
}

void DFS(int u) {
	dfnid[dfn[u] = ++dcnt] = u;
	rep(i, 1, W) fa[u][i] = fa[fa[u][i-1]][i-1];
	for (int i = hed[u]; i; i = nxt[i]) {
		if (to[i] != fa[u][0]) {
			fa[to[i]][0] = u;
			dep[to[i]] = dep[u] + 1;
			sum[to[i]] = sum[u] + w[i];
			DFS(to[i]);
		}
	}
	rfn[u] = dcnt;
}

int getLCA(int u, int v) {
	if (dep[u] < dep[v]) swap(u, v);
	for (int i = 0, p = dep[u] - dep[v]; p; i++, p >>= 1) {
		if (p&1) u = fa[u][i];
	}
	if (u == v) return u;
	req(i, W, 0) {
		if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
	}
	return fa[u][0];
}

int RMQlca(int l, int r) {
	int k = __lg(r-l+1);
	return getLCA(rmqLCA[l][k], rmqLCA[r - (1<<k) + 1][k]);
}

//可持久化线段树

#define lson tr[u].lc, l, mid
#define rson tr[u].rc, mid+1, r
#define vertex int &u, int l = 1, int r = n

int nodecnt;
int root[N+5];
struct tnode {
	int lc, rc, sum;
} tr[N * (W+10) + 5];

void Build(vertex) {
	if (!u) u = ++nodecnt;
	if (l == r) return ;
	int mid = (l+r) >> 1;
	Build(lson);
	Build(rson);
}

void Update(int pre, int pos, int val, vertex) {
	tr[u = ++nodecnt] = tr[pre];
	tr[u].sum += val;
	if (l == r) return ;
	int mid = (l+r) >> 1;
	if (pos <= mid) Update(tr[pre].lc, pos, val, lson);
	if (pos > mid) Update(tr[pre].rc, pos, val, rson);
}

int Query(int ql, int qr, int u, int l = 1, int r = n) {
	if (ql <= l && r <= qr) return tr[u].sum;
	int mid = (l+r) >> 1;
	if (qr <= mid) return Query(ql, qr, lson);
	if (ql > mid) return Query(ql, qr, rson);
	return Query(ql, qr, lson) + Query(ql, qr, rson);
}

int getlr(int u, int l, int r) {
	return Query(l, r, root[rfn[u]]) - Query(l, r, root[dfn[u] - 1]);
}

#undef lson
#undef rson
#undef vertex

//可持久化线段树（结束）

int main() {
	freopen("memory.in", "r", stdin);
	freopen("memory.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> q;
	for (int i = 1, u, v, w; i < n; i++) {
		cin >> u >> v >> w;
		Addedge(u, v, w);
		Addedge(v, u, w);
	}

	DFS(1);
	rep(i, 1, n) rmqLCA[i][0] = i;
	rep(j, 1, W) rep(i, 1, n) {
		rmqLCA[i][j] = rmqLCA[i][j-1];
		if (i + (1 << j-1) <= n) rmqLCA[i][j] = getLCA(rmqLCA[i][j], rmqLCA[i + (1 << j-1)][j-1]);
	}

	Build(root[0]);
	rep(i, 1, n) Update(root[i-1], dfnid[i], 1, root[i]);

	for (LL l, r, p; q--;) {
		cin >> p >> l >> r;
		l ^= lstans, r ^= lstans, p ^= lstans;
		int lrLCA = RMQlca(l, r);
		if (dfn[p] < dfn[lrLCA] || dfn[p] > rfn[lrLCA]) lstans = sum[p] + sum[lrLCA] - sum[getLCA(p, lrLCA)] * 2;
		else {
			int pA = p;
			req(i, W, 0) {
				if (fa[pA][i] && getlr(fa[pA][i], l, r) == 0) pA = fa[pA][i];
			}
			lstans = getlr(p, l, r) ? 0 : sum[p] - sum[fa[pA][0]];
		}
//		cout << l << ',' << r << ' ' << p << " = ";
		cout << lstans << '\n';
	}
	return 0;
}
